package com.xunk.scene.enums;

import com.xunk.common.core.interfaces.EnumValidateInterface;
import com.xunk.common.core.utils.StringUtils;
import lombok.Getter;

/**
 * @ProjectName: HIM
 * @Package: com.xunk.scene.enums
 * @ClassName: CompareOperatorEnum
 * @Author: luanzhiwei
 * @Description: 操作比较符枚举
 * @Date: 2021/5/12 14:38
 * @Version: 1.0
 */
@Getter
public enum CompareOperatorEnum implements EnumValidateInterface {

    GT("GT", "大于"),
    LT("LT", "小于"),
    BT("BT", "介于"),
    EQ("EQ", "等于"),
    GTEQ("GTEQ", "大于等于"),
    LTEQ("LTEQ", "小于等于");

    CompareOperatorEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 码值
     */
    private String code;
    /**
     * 描述
     */
    private String desc;

    /**
     * 根据code获取枚举
     *
     * @param code
     * @return
     */
    public static CompareOperatorEnum getByCode(String code) {
        for (CompareOperatorEnum value : CompareOperatorEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 根据code获取描述
     *
     * @param code
     * @return
     */
    public static String getDescByCode(String code) {
        for (CompareOperatorEnum value : CompareOperatorEnum.values()) {
            if (value.getCode().equals(code))
                return value.getDesc();
        }
        return StringUtils.EMPTY;
    }

    /**
     * 判断是否是可用枚举
     *
     * @param code
     * @return
     */
    @Override
    public Boolean isValidEnum(String code) {
        for (CompareOperatorEnum value : CompareOperatorEnum.values()) {
            if (value.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }
}
